package com.tamo.ppresta.adapter;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.tamo.ppresta.R;
import com.tamo.ppresta.bean.GetRecommendItemsBean;
import com.tamo.ppresta.bean.GetReconmmendAppsBean;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;

/**
 * @author yeyang
 * @name ppresta
 * @class name：com.tamo.ppresta.adapter
 * @class describe
 * @time 2022/12/27 20:15
 * @change
 * @chang time
 * @class describe
 */
public class HomeAdapterBackup extends BaseMultiItemQuickAdapter<GetRecommendItemsBean.RecommendItemsEntity, BaseViewHolder> {

    private ArrayList<GetRecommendItemsBean.RecommendItemsEntity> mData = new ArrayList<>();
    private ArrayList<GetReconmmendAppsBean.RecommendAppListEntity> mApps = new ArrayList<>();
    private Boolean isFootView = false;//是否添加了FootView

    public HomeAdapterBackup() {
    }

    public HomeAdapterBackup(@Nullable ArrayList<GetRecommendItemsBean.RecommendItemsEntity> data) {
        super(data);
        addItemType(0, R.layout.layout_item_home);
        addItemType(1, R.layout.layout_item_home_app);
        mData.addAll(data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, GetRecommendItemsBean.RecommendItemsEntity itemsEntity) {
        if (baseViewHolder.getItemViewType() == 0) {
            if (itemsEntity.getProductLogoUrl() != null) {
                ImageView ivItemIcon = baseViewHolder.findView(R.id.iv_item_icon);
                Glide.with(getContext()).load(itemsEntity.getProductLogoUrl()).into(ivItemIcon);
            }
            if (!itemsEntity.getProductName().isEmpty()) {
                baseViewHolder.setText(R.id.tv_item_title, itemsEntity.getProductName());
            }
            baseViewHolder.setText(R.id.tv_item_jine, "$" + itemsEntity.getMaxAmount());
            baseViewHolder.setText(R.id.tv_item_baifen, itemsEntity.getInterestRate());
            baseViewHolder.setText(R.id.tv_item_date, itemsEntity.getFastPassDay());
            TextView tvItemState = baseViewHolder.findView(R.id.tv_item_state);
            switch (itemsEntity.getUserStatus()) {
                case 0:
                    break;
                case 1:
                    break;
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    break;
                case 6:
                    break;
                case 7:
                    break;
                case 8:
                    break;
                case 9:
                    break;
                case 10:
                    break;
                case 11:
                    break;
                case 12:
                    break;
                case 13:
                    break;
            }
        } else {

        }
    }

    @Override
    public int getItemCount() {
        // TODO: 2022/12/29 目前没有推荐
//        return mData.size() + mApps.size();
        return mData.size();
//        return mData.size() + 1;
    }

    @Override
    public int getItemViewType(int position) {
//        if (position + 1 >= mData.size() + 1) {
//            return 1;
//        } else {
//            return super.getItemViewType(position);
//        }
        if (isFootView){
            return 1;
        }else {
            return 0;
        }
    }

    public ArrayList<GetReconmmendAppsBean.RecommendAppListEntity> getApps() {
        return mApps;
    }

    public void setApps(boolean isFoot,ArrayList<GetReconmmendAppsBean.RecommendAppListEntity> apps) {
        mApps = apps;
        isFootView = isFoot;
    }

    public void setData(ArrayList<GetRecommendItemsBean.RecommendItemsEntity> recommendItemsEntities) {
        mData.clear();
        mData.addAll(recommendItemsEntities);
    }

    public ArrayList<GetRecommendItemsBean.RecommendItemsEntity> getRecommendApi() {
        return mData;
    }
}